package com.kaigejava.springwebsocket.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/")
@Slf4j
public class LoginController {



    /**
     * 登陆页面
     * @return
     */
    @RequestMapping(value = "login",method = RequestMethod.GET)
    public String loginPage(){
        log.info("=======");
        return "/login";
    }

    @RequestMapping(value = "login",method = RequestMethod.POST)
    public String login(HttpSession httpSession, String userName){
        httpSession.setAttribute("userName",userName);
        return "chatroom";
    }

    @RequestMapping("logout")
    public String logout(HttpSession httpSession){
        httpSession.removeAttribute("userName");
        return "/login";
    }
}
